﻿// Copyright (c) 2012 - 2020 Jared Zheng <jaredz at outlook dot com>
// Buddha Framework is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
//          http://license.coscl.org.cn/MulanPSL2
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.
//
// Create : 2012-12-01 version 0.1 Jared Zheng <jaredz at outlook dot com>
// Update : 2018-12-05 version 3.1.5 Jared Zheng <jaredz at outlook dot com>

#ifndef __PACKET_INL__
#define __PACKET_INL__

#pragma once

///////////////////////////////////////////////////////////////////////////////////////////////////////////
// CPAKHeadBase : 信令包数据头
INLINE CPAKHeadBase::CPAKHeadBase(UEVENT uEvent, UTYPE uType, UACK uAck)
: m_uEvent(uEvent)
, m_uType(uType)
, m_uAck(uAck)
, m_uSrvId(0)
{
}

INLINE CPAKHeadBase::~CPAKHeadBase(void)
{
}

INLINE CPAKHeadBase::CPAKHeadBase(const CPAKHeadBase& aSrc)
: m_uEvent(aSrc.m_uEvent)
, m_uType(aSrc.m_uType)
, m_uAck(aSrc.m_uAck)
, m_uSrvId(aSrc.m_uSrvId)
{
}

INLINE CPAKHeadBase& CPAKHeadBase::operator=(const CPAKHeadBase& aSrc)
{
    if (&aSrc != this)
    {
        m_uEvent = aSrc.m_uEvent;
        m_uType  = aSrc.m_uType;
        m_uAck   = aSrc.m_uAck;
        m_uSrvId = aSrc.m_uSrvId;
    }
    return (*this);
}

INLINE size_t CPAKHeadBase::Length(void)
{
    return (sizeof(UEVENT) + sizeof(UTYPE) + sizeof(UACK) + sizeof(USRVID));
}

INLINE void CPAKHeadBase::Serialize(CStream& Stream)
{
    if (Stream.IsRead())
    {
        Stream >> m_uEvent >> m_uType >> m_uAck >> m_uSrvId;
    }
    else
    {
        Stream << m_uEvent << m_uType << m_uAck << m_uSrvId;
    }
}

INLINE UEVENT CPAKHeadBase::GetEvent(void)
{
    return m_uEvent;
}

INLINE void CPAKHeadBase::SetEvent(UEVENT uEvent)
{
    m_uEvent = uEvent;
}

INLINE UTYPE CPAKHeadBase::GetType(void)
{
    return m_uType;
}

INLINE void CPAKHeadBase::SetType(UTYPE uType)
{
    m_uType = uType;
}

INLINE UACK CPAKHeadBase::GetAck(void)
{
    return m_uAck;
}

INLINE void CPAKHeadBase::SetAck(UACK uAck)
{
    m_uAck = uAck;
}

INLINE USRVID CPAKHeadBase::GetSrvId(void)
{
    return m_uSrvId;
}

INLINE void CPAKHeadBase::SetSrvId(USRVID uSrvId)
{
    m_uSrvId = uSrvId;
}

INLINE void CPAKHeadBase::ResetHead(UEVENT uEvent, UTYPE uType, UACK uAck)
{
    SetEvent(uEvent);
    SetType(uType);
    SetAck(uAck);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////
// CTPAKHeadBase : 信令包数据头模板
template <UEVENT uEvent, UTYPE uType>
INLINE CTPAKHeadBase<uEvent, uType>::CTPAKHeadBase(UACK uAck)
: CPAKHeadBase(uEvent, uType, uAck)
{
}

template <UEVENT uEvent, UTYPE uType>
INLINE CTPAKHeadBase<uEvent, uType>::~CTPAKHeadBase(void)
{
}

template <UEVENT uEvent, UTYPE uType>
INLINE CTPAKHeadBase<uEvent, uType>::CTPAKHeadBase(const CTPAKHeadBase<uEvent, uType>& aSrc)
: CPAKHeadBase(aSrc)
{
}

template <UEVENT uEvent, UTYPE uType>
INLINE CTPAKHeadBase<uEvent, uType>& CTPAKHeadBase<uEvent, uType>::operator=(const CTPAKHeadBase<uEvent, uType>& aSrc)
{
    if (&aSrc != this)
    {
        CPAKHeadBase::operator=(aSrc);
    }
    return (*this);
}

#endif // __PACKET_INL__
